package example.demo;

import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;

public class Test {
    static int count = 500;
    static CountDownLatch latch = new CountDownLatch(count);
    static CountDownLatch main = new CountDownLatch(count);

    public static void main(String[] args) throws InterruptedException {
        ReadWriteList<String> readWriteList = new ReadWriteList<>(new ArrayList<>());
        for (int i = 0; i < count; i++) {
            new Thread(() -> {
                try {
                    latch.await();
                } catch (InterruptedException e) {
                }
                for (int j = 0; j < 1000; j++) {//500*1000
                    readWriteList.add("wahahaa");
                }
                main.countDown();
            }).start();
            latch.countDown();
        }
        main.await();
        int size = readWriteList.size();
        System.out.println("size = " + size);//size = 500000
    }
}
